package com.ruoyi.paint.admin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.paint.admin.domain.Cxcar;
import com.ruoyi.paint.admin.service.ICxcarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆总体信息Controller
 *
 * @author itchen
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/paint/cxcar")
public class CxcarController extends BaseController {
    @Autowired
    private ICxcarService cxcarService;
    String fileName = "C:\\Users\\Asus\\Desktop\\导出\\导出.xlsx";

    /**
     * 查询车辆总体信息列表
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cxcar cxcar) {
        startPage();
        List<Cxcar> list = cxcarService.selectCxcarList(cxcar);
        return getDataTable(list);
    }

    /**
     * 导出车辆总体信息列表
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:export')")
    @Log(title = "车辆总体信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cxcar cxcar)
    {
        List<Cxcar> list = cxcarService.selectCxcarList(cxcar);
        ExcelUtil<Cxcar> util = new ExcelUtil<Cxcar>(Cxcar.class);
        util.exportExcel(response, list, "车辆总体信息数据");
    }





    /**
     * 获取车辆总体信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cxcarService.selectCxcarById(id));
    }

    /**
     * 新增车辆总体信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:add')")
    @Log(title = "车辆总体信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cxcar cxcar) {
        return toAjax(cxcarService.insertCxcar(cxcar));
    }

    /**
     * 修改车辆总体信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:edit')")
    @Log(title = "车辆总体信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cxcar cxcar) {
        return toAjax(cxcarService.updateCxcar(cxcar));
    }

    /**
     * 删除车辆总体信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cxcar:remove')")
    @Log(title = "车辆总体信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cxcarService.deleteCxcarByIds(ids));
    }




}
